import React, { useState, useEffect } from 'react';
import { Button, Drawer, Descriptions } from 'antd';
import { useSelector, useDispatch } from "umi"

type Props = {
  openInfo: boolean,
  infoClose(value: boolean): void
}

const OrderInfo = (props: Props) => {
  const [infoAddress, setInfoAddress]: any = useState()
  const [info, setInfo]: any = useState()
  const orderState = useSelector((state: { order: any, updateOrder: any }) => {
    //state整个仓库i数据，product是仓库命名空间
    // console.log("cang",state.order.updateOrder);
    return state.order
  })

  useEffect(() => {
    if (orderState.updateOrder.length > 0) {
      console.log("orderState", orderState.updateOrder[0]);
      setInfoAddress(orderState.updateOrder[0].address)
      setInfo(orderState.updateOrder[0])
    }

  }, [orderState])

  const onClose = () => {
    props.infoClose(false)
  };


  return (
    <>

      <Drawer size='large' title="订单详情" placement="right" onClose={onClose} open={props.openInfo}>
        {props.openInfo == true ?<><Descriptions title="收货信息" column={2} size='middle'>
          <Descriptions.Item label="用户昵称">{infoAddress.nickname}</Descriptions.Item>
          <Descriptions.Item label="收货人">{infoAddress.name}</Descriptions.Item>
          <Descriptions.Item label="联系电话">{infoAddress.phone}</Descriptions.Item>
          <Descriptions.Item label="收货地址">{infoAddress.site}</Descriptions.Item>
        </Descriptions>
        <Descriptions title="收货信息" column={2} size='middle'>
        <Descriptions.Item label="订单ID">{info.order_id}</Descriptions.Item>
        <Descriptions.Item label="订单状态">{info.status}</Descriptions.Item>
        <Descriptions.Item label="商品总价">{info.pay.pay_actual}</Descriptions.Item>
        <Descriptions.Item label="商品总数">{info.goods_count}</Descriptions.Item>
        <Descriptions.Item label="交付邮费">{info.pay.pay_freight}</Descriptions.Item>
        <Descriptions.Item label="赠送积分">{info.pay.pay_integral}</Descriptions.Item>
        <Descriptions.Item label="创建时间">{info.create_time}</Descriptions.Item>
        <Descriptions.Item label="支付时间">{info.pay.pay_time}</Descriptions.Item>
        <Descriptions.Item label="支付方式">{info.pay.pay_type}</Descriptions.Item>
        </Descriptions></>: null}
      </Drawer>
      {/* <Drawer title="订单信息" placement="right" onClose={onClose} open={props.openInfo}>
        
      </Drawer> */}
    </>
  )
}

export default OrderInfo

// 订单ID：cp156416072256323584订单状态：未支付
// 商品总数：2商品总价：258.00
// 交付邮费：24.00优惠券金额：258.00
// 用户等级优惠：0.00付费会员优惠：0
// 积分抵扣：0.00实际支付：24.00
// 赠送积分：200创建时间：2023-03-08 15:01:37支付时间：支付方式：推广人：180****0652/38768